'use strict';
const db=uniCloud.database();
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	const userId = event.userId || ''
	let data={}
	let result 
	if(!userId){
		//添加数据到云数据库
		data={
			username:event.username,
			password:event.password,
			account:event.account
		}
		result = await db.collection('user').add(data)
	}else{
		console.log('edit ')
		data={
			username:event.username,
		}
		result = await db.collection('user').doc(userId).update(data)
	}
		
	if(result){
		return {
			code:200,
			msg:"操作成功"
		}
	}else{
		return {
			code:501,
			msg:"操作失败"
		}
	}
//返回数据给客户端
return event
};
